package 剑指offer.Month7_07.day18;

public class 删除链表中重复的节点 {
    public ListNode deleteDuplication(ListNode pHead) {
        if(pHead == null) return null;
        ListNode node = new ListNode(-1);
        node.next = pHead;
        ListNode tmp = node;
        ListNode slow = pHead;
        ListNode fast = pHead.next;
        while(slow != null && slow.next != null){
            if(slow.val != fast.val){
                tmp = slow;
                slow = fast;
                fast = slow.next;
            }else{
                while(fast != null && fast.val == slow.val){
                    fast = fast.next;
                }
                slow = tmp;
                slow.next = fast;
            }
        }
        return node.next;
    }
}
